<%--
  Created by IntelliJ IDEA.
  User: 王一同
  Date: 2021/11/20
  Time: 12:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css"/>
<script src="${pageContext.request.contextPath}/layui/layui.js"></script>
<style>
    .layui-form-item label {
        font-weight: bolder;
        font-size: 16px;
    }

</style>
<form class="layui-form" hidden id="form" lay-filter="formTest" style="margin-top: 30px;margin-bottom: 30px">
    <input type="hidden" name="e_password" value="${sessionScope.employee.e_password}">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">编号:</label>
            <div class="layui-input-inline">
                <input type="text" name="e_number" value="${sessionScope.employee.e_number}" readonly="readonly"
                       required
                       lay-verify="required" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">姓名:</label>
            <div class="layui-input-inline">
                <input type="text" name="e_name" value="${sessionScope.employee.e_name}" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>

        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">性别:</label>
            <div class="layui-input-block" style="width: 200px">
                <select name="e_sex" lay-verify="required">
                    <option value="">--请选择--</option>
                    <option value="男" ${sessionScope.employee.e_sex=='男' ? "selected":""}>男</option>
                    <option value="女" ${sessionScope.employee.e_sex=='女' ? "selected":""}>女</option>

                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">年龄:</label>
            <div class="layui-input-inline">
                <input type="text" name="e_age" value="${sessionScope.employee.e_age}" readonly="readonly"
                       required
                       lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">所属部门:</label>
            <div class="layui-input-inline">
                <input type="text" name="d_name" value="${sessionScope.employee.d_name}" readonly="readonly"
                       lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">入职时间:</label>
            <div class="layui-input-inline">
                <input type="text" name="e_indate" value="${sessionScope.employee.e_indate}" readonly="readonly"
                       required
                       lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">职位:</label>
            <div class="layui-input-inline">
                <input type="text" name="r_name" value="${sessionScope.employee.r_name}" readonly="readonly" required
                       lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">身份证号:</label>
            <div class="layui-input-inline">
                <input type="text" name="e_sid" value="${sessionScope.employee.e_sid}" required lay-verify="required"
                       readonly="readonly"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">手机号:</label>
            <div class="layui-input-inline">
                <input type="tel" name="e_tel" value="${sessionScope.employee.e_tel}" lay-verify="required|phone"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">地址:</label>
            <div class="layui-input-inline">
                <input type="text" name="e_address" value="${sessionScope.employee.e_address}" required
                       lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>

    <div style="text-align: center">
        <button type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="demo">修改</button>
        <button type="button" class="layui-btn  layui-btn-primary" id="cancel">取消</button>
    </div>
</form>
<body>
<div class="layui-row layui-col-space1">
    <div class="layui-row layui-col-space1">
        <div class="layui-col-md5">
            <div class="grid-demo grid-demo-bg1"
                 style="font-weight: bolder;font-size: 24px;margin-top:4px;padding-left: 70px">个人信息
            </div>
            <hr>
            <div class="layui-upload">
                <div class="layui-upload-list">
                    <img class="layui-upload-img" src="${sessionScope.employee.e_url}" style="width: 115px;padding-left:60px; height: 130px;" id="demo1">
                    <p id="demoText"></p>
                </div>
                <button type="button" class="layui-btn " id="test1" style="margin-left: 70px">上传图片
                </button>
            </div>
            <div style="margin-top: 100px;margin-left: 110px">
                <button class="layui-btn " id="sub" style="margin-left: 70px">修改信息</button>
            </div>

        </div>
        <div class="layui-col-md5">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 32px;">
                <legend>
                    基本信息
                </legend>
            </fieldset>

            <form class="layui-form" action="" lay-filter="form">
                <input type="hidden" name="e_password" value="${sessionScope.employee.e_password}">
                <div class="layui-form-item">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="e_number" value="${sessionScope.employee.e_number}" readonly="readonly"
                               style="border: none" required lay-verify="required" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="e_name" value="${sessionScope.employee.e_name}" required
                               readonly="readonly"
                               style="border: none" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">所属部门</label>
                    <div class="layui-input-inline">
                        <input type="text" name="d_name" value="${sessionScope.employee.d_name}" readonly="readonly"
                               required style="border: none" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">入职时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="e_indate" value="${sessionScope.employee.e_indate}" readonly="readonly"
                               required style="border: none" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">职位</label>
                    <div class="layui-input-inline">
                        <input type="text" name="r_name" value="${sessionScope.employee.r_name}" required
                               readonly="readonly"
                               style="border: none" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">身份证号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="e_sid" value="${sessionScope.employee.e_sid}" required
                               readonly="readonly"
                               style="border: none" lay-verify="required" readonly="readonly"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">手机号</label>
                    <div class="layui-input-inline">
                        <input type="tel" name="e_tel" id="" value="${sessionScope.employee.e_tel}" required
                               readonly="readonly"
                               style="border: none" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">地址</label>
                    <div class="layui-input-inline">
                        <input type="text" name="e_address" value="${sessionScope.employee.e_address}" required
                               readonly="readonly"
                               style="border: none" lay-verify="required"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
</body>
<script>

    layui.use(['table', 'jquery', 'form', 'upload'], function () {
        var table = layui.table;
        var $ = layui.jquery;
        var form = layui.form;
        var upload = layui.upload;
        var index;


        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: '${pageContext.request.contextPath}/login/upload' //改成您自己的上传接口
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
        , done: function (res) {
                //如果上传失败
                if (res.code == 1) {
                    return layer.msg('上传成功');
                //    上传成功就刷新当前头像
                }

            }
        , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });


        $("#sub").click(function () {
            index = layer.open({
                title: '修改基本信息'
                , type: 1
                , content: $("#form")
                , area: ['714px', '440px']
            });
        })

        //点击取消就关闭弹框
        $("#cancel").click(function () {
            layer.close(index);
        })

        //监听提交
        form.on('submit(demo)', function (data) {
            //   获取表单全部数据
            var datas = data.field
            if ('${sessionScope.employee.e_name}' != datas.e_name || '${sessionScope.employee.e_age}' != datas.e_age || '${sessionScope.employee.e_tel}' != datas.e_tel || '${sessionScope.employee.e_address}' != datas.e_address||'${sessionScope.employee.e_sex}'!=datas.e_sex
            ) {
                $.ajax({
                    url: '${pageContext.request.contextPath}/login/updateMassage',
                    data: form.val("formTest"),
                    dataType: "json",
                    type: "post",
                    success: function (resObj) {
                        if (resObj.code == 1) {
                            layer.msg(resObj.msg, {icon: 1})
                            //刷新右侧表格  给右侧表格重新赋值
                            form.val("form", form.val("formTest"));
                            //    关闭弹框
                            layer.close(index);
                        } else {
                            layer.msg(resObj.msg, {icon: 5})
                        }

                        //    刷新右侧form表单数据
                    }
                })


            } else {
                layer.msg("请填写您要修改的数据", {icon: 3})
            }
        });

    });

</script>
</html>
